
package com.lemon.utils;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * <p>Title: PlatUtils</p>
 * <p>Description: 
 * </p>
 * <p>Company: </p>
 * @author Ran_cc
 * @date 2018年11月27日
 * @版本 V 1.0 
 */
public class PlatUtils {
	private static final String gdkey = "1b76797c593dff1bd16b6c80dc986b6d";
	
	
	/**
	 * <b>Description:<blockquote> 通过地址位置获得经纬度
	 * </blockquote></b>
	 * 
	 * @Title: getLocationByAddress
	 * @param addr
	 * @return
	 * @author Ran_cc
	 * @date 2018年11月27日
	 */
	public static String getLocationByAddress(String addr) {
		Map<String , String> map = new  HashMap<String , String>();
		map.put("key" , gdkey);
		map.put("address" , addr);
		String doGet = HttpUtil.doGet("https://restapi.amap.com/v3/geocode/geo" , map);
		if (StringUtil.isEmpty(doGet)) {
			return "";
		}
		JSONObject js = (JSONObject) JSONObject.parse(doGet);
		JSONArray array = js.getJSONArray("geocodes");
		if (array.size() <= 0) {
			return "";
		}
		JSONObject jss = (JSONObject) array.get(0);
		String loc = jss.getString("location");
		return loc;
	}
	public static void main(String[] args) {
		String ss = "浙江省杭州市余杭区马鞍山雅苑焗烤官";
		String locationByAddress = getLocationByAddress(ss);
		System.out.println(locationByAddress);
	}
	
}
